<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="项目编号">
              <j-input placeholder="请输入项目编号" v-model="queryParam.xmbh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="项目名称">
              <j-input placeholder="请输入项目名称" v-model="queryParam.xmmc"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="10" :sm="24">
            <a-form-item label="发布时间">
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.fbsj_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.fbsj_end"></j-date>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="结算单号">
              <j-input placeholder="请输入项目单号" v-model="queryParam.jsdh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="3" :lg="7" :md="5" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a v-if="record.qycwzt == 0" @click="payModal(record)">结算</a>
          <a-divider type="vertical" />
          <a @click="handleDetail(record)">详情</a>
        </span>
      </a-table>
    </div>

    <a-modal :visible="payModalShow" @ok="payOk" @cancel="payCancel" :width="600" title="填写结算信息" :confirm-loading="loading">
      <a-form :form="form" :label-col="{ span: 7 }" :wrapper-col="{ span: 15 }">
        <a-form-item style="margin-bottom: 0px;" label="项目名称"> {{xmmc}} </a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="结算单号"> {{jsdh}} </a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="结算状态"> 待结算 </a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="付款金额">{{zje}} 元</a-form-item>
<!--        <a-form-item style="margin-bottom: 0px;" label="付款账号">{{qykh}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="户名">{{qyzhm}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="开户行">{{qykhh}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="收款人户名">{{ptzhm}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="收款人账号">{{ptkh}}{{qydmanbr}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="收款人开户行">{{ptkhh}}</a-form-item>-->
        <a-form-item style="margin-bottom: 0px;" label="结算银行账户名">{{ptzhm}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="结算银行账号">{{ptkh}}{{qydmanbr}}</a-form-item>
        <a-form-item style="margin-bottom: 0px;" label="结算银行开户行">{{ptkhh}}</a-form-item>
        <!--<a-form-item style="margin-bottom: 8px;" label="付款回单银行流水号">
          <a-input v-decorator="['ywckh',{rules: [{ required: true, message: '请输入银行流水号!'}]}]" ></a-input>
        </a-form-item>
        <a-form-item label="上传付款凭证">
          <j-image-upload isMultiple v-decorator="['fkpz',{rules: [{ required: true, message: '请上传付款凭证!'}]}]"></j-image-upload>
        </a-form-item>-->
      </a-form>
      <p style="color:red; padding: 10px 40px;"> 注：按照系统操作流程，结算前必须先将待结算金额转账到页面提示的对应<span style="margin-left: 30px;">户名和账号中</span>，确认已到账后,再在此进行结算操作！</p>

    </a-modal>

    <lhyg-qy-finance-modal ref="modalForm" @ok="modalFormOk"></lhyg-qy-finance-modal>
  </a-card>
</template>

<script>

  import { postAction } from '@/api/manage'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LhygQyFinanceModal from './modules/LhygQyFinanceModal'
  import JImageUpload from '@/components/jeecg/JImageUpload'
  import JDate from '@/components/jeecg/JDate.vue'
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: 'LhygQyFinanceList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LhygQyFinanceModal,
      JImageUpload,
      JDate,
      JInput
    },
    data () {
      return {
        description: '企业财务管理管理页面',
        form: this.$form.createForm(this),
        // 表头
        columns: [
          {
            title:'结算单号',
            align:"center",
            dataIndex: 'jsdh'
          },
          {
              title:'项目编号',
              align:"center",
              dataIndex: 'xmbh'
          },
          {
              title:'项目协议编号',
              align:"center",
              dataIndex: 'xmxybh'
          },
          {
              title:'项目名称',
              align:"center",
              dataIndex: 'xmmc'
          },
          {
              title:'发布时间',
              align:"center",
              dataIndex: 'fbsj'
          },
          {
            title:'结算金额',
            align:"center",
            dataIndex: 'jsje'
          },
          {
            title:'本次应付个税',
            align:"center",
            dataIndex: 'sigtaxje'
          },
          {
            title:'平台服务费',
            align:"center",
            dataIndex: 'fwfje'
          },
          {
            title:'总金额',
            align:"center",
            dataIndex: 'zje'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/project/lhygQyFinance/list",
          edit: "/project/lhygQyFinance/edit",
          queryYe: "/project/lhygQyFinance/queryYe",
          exportXlsUrl: "/project/lhygQyFinance/exportXls",
          importExcelUrl: "project/lhygQyFinance/importExcel",
          getPjComplete: "/project/lhygProjectIndividual/getPjComplete",
          updateStatus: "/project/lhygWxMoneyDetail/updateStatus"
        },
        dictOptions:{},
        payModalShow: false,
        loading: false,
        recordId: '',
        xmmc: '',
        jsdh: '',
        zje: '',
        qykh: '',
        qydmanbr: '',
        qyzhm: '',
        qykhh: '',
        ptzhm: '',
        ptkh: '',
        ptkhh: '',
        ywckh: '',
        fkpz: '',
        xmbh: '',
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      payModal(record){
          const that = this;
          that.form.resetFields();
          that.recordId = record.id;
          that.xmmc = record.xmmc;
          that.jsdh = record.jsdh;
          that.zje = record.zje;
          that.qykh = record.qykh;
          that.qydmanbr = record.qydmanbr;
          that.qyzhm = record.qyzhm;
          that.qykhh = record.qykhh;
          that.ptzhm = record.ptzhm;
          that.ptkh = record.ptkh;
          that.ptkhh = record.ptkhh;
          that.xmbh = record.xmbh;
          that.payModalShow = true;
      },
      payOk(){
        let that = this;
        that.loading = true;
        let formData=new FormData();
        formData.append("id",that.recordId);
        // 上传凭证并验证，调银行接口
        postAction(that.url.queryYe, formData).then((res)=>{
            if(res.success){
                that.payModalShow = false;
                that.loading = false;
                that.loadData();
                that.payList();
            } else {
                that.loading = false;
                if(res.message != ""){
                    that.$message.warning(res.message);
                }
            }
        })
      },
      payCancel(){
          const that = this;
          that.payModalShow = false;
          that.recordId = '';
          that.xmmc = '';
          that.jsdh = '';
          that.zje = '';
          that.qykh = '';
          that.qydmanbr = '';
          that.qyzhm = '';
          that.qykhh = '';
          that.ptzhm = '';
          that.ptkh = '';
          that.ptkhh = '';
      },
      getPjComplete(){
          // 验证是否全部完成结算
          let formData=new FormData();
          formData.append("xmbh", this.xmbh);
          postAction(this.url.getPjComplete, formData).then((res)=>{
          })
      },
      payList(){
        const that = this;
        let formData=new FormData();
        formData.append("id",that.recordId);
        postAction(that.url.edit, formData).then((res)=>{
            if(res.success){
                that.getPjComplete();
            }
        })
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>